/*
 * Copyright (c) 2011 Imre Fazekas.
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * Neither the name of the Brillien nor the names of its
 * terms and concepts may be used to endorse or promote products derived from this
 * software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

package com.vii.brillien.kernel.axiom.atomic;

import com.vii.brillien.kernel.BrillienException;
import com.vii.brillien.kernel.axiom.transport.Communication;

import java.util.Collection;

/**
 * Commander is a central management object in Brillien. Features:
 * - maintain and manage all Presence instance in the running system
 * - common interface for all Presence object to able to collect information about other Presence objects
 * - registration-based Presence management
 *
 * The Commander object is a Unit, so Brillien is a Commander object graph and every Commander object may contain any Presence object, a Commander as well in fact. However, this would signify a very-very complex system. In most cases, a single Liaison is sufficient for all purposes.
 */
public interface Commander<P extends PresenceManager, C extends Communication, R> extends Flow<P, C, R> {

    /**
     * Registers a Presence. It is performed after loading a component from the deployment directory.
     * @param Presence class reference for the Presence type
     * @param <T> generic type representing the Presence origin
     * @return name of the Presence component
     */
    <T extends Presence> String     registerPresence( Class<T> Presence ) throws BrillienException;

    /**
     * Makes a presence "clone". An already registered presence will be registered with a new name, thus reusing entity. Name must be unique. 
     * @param Presence class reference for the Presence type
     * @param cloneName name of the clone
     * @param <T> generic type representing the Presence origin
     * @return name of the Presence component
     */
    <T extends Presence> String     registerPresence( Class<T> Presence, String cloneName ) throws BrillienException;
    
    /**
     * Makes a presence "clone". An already registered presence will be registered with a new name, thus reusing entity. The Presence type will be identified by its publishing name. Name must be unique.
     * @param originalName name of the original Presence
     * @param cloneName name of the clone
     * @return name of the Presence component
     */
    String                          registerPresence(String originalName, String cloneName) throws BrillienException;

    /**
     * Unregisters a Presence by its name.
     * @param PresenceName presence to be unregistered
     */
    void                            unregisterPresence( String PresenceName ) throws BrillienException;

    /**
     * @return the list of published components
     */
    Collection<String>              getPresenceNames();

    /**
     * Tells whether a Presence with the given name exists
     * @param name name of the presence
     */
    boolean                         hasPresence( String name );

    /**
     * @return list of managers of published components
     */
    Collection<P>                   getPresenceManagers();

    /**
     * Get the Presence Manager of a Presence type by its name
     * @param name name of the Presence type
     * @return Presence Manager of the given Presence type
     */
    P                               getPresenceManagerOf( String name );

    /**
     * Sets the name of the Presence providing SSO functionality
     */
    void                            setSSOPresenceName( String PresenceName );

    /**
     * Sets the name of the Presence providing SSO functionality
     */
    void                            setApyKeyPresenceName( String PresenceName );

}
